using System;
using System.Reflection;
using System.Windows.Forms;
using WindowsLive.Writer.Api;
using WindowsLive.Writer.Extensibility.BlogClient;
using WindowsLive.Writer.PostEditor;

namespace Toth.WLW.Plugins
{
	
	/// <summary>
	/// xPollinate Plugin Class
	/// </summary>
	[WriterPlugin(
		XPollinate.PluginGuid,
		XPollinate.PluginTitle,
		Description = ThisAssembly.AssemblyDescription,
		HasEditableOptions = true,
		PublisherUrl = XPollinate.PluginUrl, 
		ImagePath="xPollinate.png")]
	[InsertableContentSource(XPollinate.PluginTitle, SidebarText = XPollinate.PluginTitle)]
	public class XPollinate : ContentSource
	{

		#region Plugin Constants

		/// <summary>
		/// The unique ID of this plugin
		/// </summary>
		public const string PluginGuid = "16BD0CD9-D374-472d-B605-3B8F0D126BE5";

		/// <summary>
		/// The title of the plugin
		/// </summary>
		public const string PluginTitle = "xPollinate";

		/// <summary>
		/// The URL for the plugin information
		/// </summary>
		public const string PluginUrl = "http://xpollinate.codeplex.com";

		#endregion

		#region User Setting Variable Names

		public static readonly string PostToBlogsOption = ThisAssembly.AssemblyTitle + "_PostToBlogs";
		public static readonly string PostToPingFMOption = ThisAssembly.AssemblyTitle + "_PostToPingFM";
		public static readonly string IncludeHeaderOption = ThisAssembly.AssemblyTitle + "_IncludeHeaderOption";
		public static readonly string HeaderTextOption = ThisAssembly.AssemblyTitle + "_HeaderTextOption";
		public static readonly string IncludeFooterOption = ThisAssembly.AssemblyTitle + "_IncludeFooterOption";
		public static readonly string FooterTextOption = ThisAssembly.AssemblyTitle + "_FooterTextOption";
		public static readonly string CommentPolicyOption = ThisAssembly.AssemblyTitle + "_CommentPolicyOption";
		public static readonly string PingPolicyOption = ThisAssembly.AssemblyTitle + "_PingPolicyOption";
		public static readonly string TargetBlogIdsOption = ThisAssembly.AssemblyTitle + "_TargetBlogIds";
		public static readonly string DefaultBlogsOption = ThisAssembly.AssemblyTitle + "_DefaultBlogs";
		public static readonly string PostSummaryOption = ThisAssembly.AssemblyTitle + "_PostSummary";
		public static readonly string SummaryCharactersOption = ThisAssembly.AssemblyTitle + "_SummaryCharacters";
		public static readonly string PingFMAPIKey = ThisAssembly.AssemblyTitle + "_PingFMAPIKey";
		public static readonly string PingFMPostToBlogs = ThisAssembly.AssemblyTitle + "_PingFMPostToBlogs";
		public static readonly string PingFMPostToMicroBlogs = ThisAssembly.AssemblyTitle + "_PingFMPostToMicroBlogs";
		public static readonly string PingFMPostToStatuses = ThisAssembly.AssemblyTitle + "_PingFMPostToStatuses";
		public static readonly string PingFMMicroBlogTemplate = ThisAssembly.AssemblyTitle + "_PingFMMicroBlogTemplate";
		public static readonly string PingFMStatusTemplate = ThisAssembly.AssemblyTitle + "_PingFMStatusTemplate";
		public static readonly string PingFMPostToBlogShortenLinks = ThisAssembly.AssemblyTitle + "_PingFMPostToBlogShortenLinks";
		public static readonly string PingFMPostToBlogBookmarkLinks = ThisAssembly.AssemblyTitle + "_PingFMPostToBlogBookmarkLinks";

		#endregion

		/// <summary>
		/// Shown when a user chooses to edit the plugin options
		/// </summary>
		/// <param name="dialogOwner"></param>
		public override void EditOptions(IWin32Window dialogOwner)
		{
			using (FormXPollinate formXPollinate = new FormXPollinate())
			{
				formXPollinate.ShowDialog(dialogOwner);
			}
		}

		/// <summary>
		/// Shown when a user chooses to Cross Post
		/// </summary>
		/// <param name="dialogOwner"></param>
		/// <param name="content"></param>
		/// <returns></returns>
		public override DialogResult CreateContent(IWin32Window dialogOwner, ref string content)
		{
			PostEditorForm form = (PostEditorForm)dialogOwner;

			BlogPost originalPost = form.GetOriginalBlogPost();

			if (originalPost == null)
			{
				MessageBox.Show(dialogOwner, Properties.Resources.ErrorUnpublished, XPollinate.PluginTitle);
				return DialogResult.Cancel;
			}

			using (FormXPollinate formXPollinate = new FormXPollinate(form.CurrentAccountId, originalPost))
			{
				return formXPollinate.ShowDialog(dialogOwner);
			}

           

		}

	}
}
